/*
 * 文件名: NoScrollerListView.java
 * 版    权：  Copyright PingAn Technology All Rights Reserved.
 * 描    述: [该类的简要描述]
 * 创建人: EX-XIAOFANQING001
 * 创建时间: 2011-12-20
 * 
 * 修改人：
 * 修改时间:
 * 修改内容：[修改内容]
 */
package app.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import app.log.APPLog;


/**
 * 自定义的不支持滚动条的ListView
 * 该类不支持Adapter的notifyDataSetChanged方法刷新
 * @author EX-XIAOFANQING001
 * @date 2011-12-20
 * @version [Android PABank C01, @2011-12-20]
 * @description
 */
public class NoScrollerListView extends LinearLayout 
{
	/**
	 * Log标签
	 */
	private static final String TAG = NoScrollerListView.class.getSimpleName();
    /**
     * 适配器
     */
    private BaseAdapter mAdapter;
    /**
     * 点击监听事件
     */
    private OnItemClickListener mOnItemClickListener;
    
    
    /**
     * [构造简要说明]
     * @param context context
     * @param attrs attrs
     */
    public NoScrollerListView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        init();
    }

    /**
     * [构造简要说明]
     * @param context context
     */
    public NoScrollerListView(Context context)
    {
        super(context);
        init();
    }
    
    /**
     * [得到适配器]<BR>
     * [功能详细描述]
     * @return
     */
    public BaseAdapter getAdapter() {
        return mAdapter;
    }

    /**
     * [初始化方法]<BR>
     * [功能详细描述]
     */
    private void init() {
        setOrientation(LinearLayout.VERTICAL);
    }
    
    /**
     * [设置适配器]<BR>
     * [功能详细描述]
     * @param adapter
     */
    public void setAdapter (BaseAdapter adapter) {
        if (adapter == null ) {
            return ;
        }
        mAdapter = adapter;
        refreshData(false);
    }
    
    /**
     * [重新刷新数据]<BR>
     * [功能详细描述]
     */
    public void refreshData(boolean flag) 
    {
        LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
        mAdapter.notifyDataSetChanged();
        removeAllViews();
        
        for (int i = 0; i<mAdapter.getCount(); i++) {
            final View itemView  = mAdapter.getView(i, null, null);
            itemView.setLayoutParams(lp);
            addView(itemView);
            
            final int position = i;
            itemView.setOnClickListener(new OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                	if(mOnItemClickListener != null){
                		mOnItemClickListener.onItemClick(null, itemView, position, 0);
                	}
                }
            });
        }
        
        requestLayout();
    }
    
    /**
     * [设置监听事件]<BR>
     * [功能详细描述]
     * @param onItemClickListener OnItemClickListener
     */
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) 
    {
    	if(onItemClickListener != null){
    		mOnItemClickListener = onItemClickListener;
    	}else{
    		APPLog.e(TAG, "OnItemClickListener监听事件不能为空！");
    	}
    }
}

